home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0069_BitMap Scaler.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-21  |  2KB  |  52 lines

  1.  
  2. TYPE
  3.   Fixed = RECORD CASE Boolean OF
  4.     True  : (w : LongInt); False : (f, i : Word);
  5.   END;
  6.  
  7. { originally by SEAN PALMER, I just mangled it  :^) }
  8. PROCEDURE ScaleBitmap(VAR bmp2scale; actualx, actualy : Byte;
  9.                       bstrtx, bstrty, bendx, bendy : Word);
  10. { These are notes I added, so they might be wrong.  :^)     }
  11. { - bmp2scale is an array [0..actualx, 0..actualy] of byte  }
  12. {   which contains the original bitmap                      }
  13. { - actualx and actualy are the actual width and height of  }
  14. {   the normal bitmap                                       }
  15. { - bstrtx and bstrty are the x and y values for the upper- }
  16. {   left-hand corner of the scaled bitmap                   }
  17. { - bendx and bendy are the lower-right-hand corner of the  }
  18. {   scaled version of the original bitmap                   }
  19. { - eg. to paste an unscaled version of a bitmap that is    }
  20. {   64x64 pixels in size in the top left-hand corner of the }
  21. {   screen, fill the array with data and call:              }
  22. {     ScaleBitmap(bitmap, 64, 64, 0, 0, 63, 63);            }
  23. { - apparently, the bitmap is read starting at (0,0) and    }
  24. {   then going to (0,1), then (0,2), etc; meaning that it's }
  25. {   not read horizontally, but vertically                   }
  26. VAR
  27.    bmp_sx, bmp_sy, bmp_cy : Fixed;
  28.    bmp_s, bmp_w, bmp_h    : Word;
  29. BEGIN
  30.      bmp_w := bendx - bstrtx + 1; bmp_h := bendy - bstrty + 1;
  31.      bmp_sx.w := actualx * $10000 DIV bmp_w;
  32.      bmp_sy.w := actualy * $10000 DIV bmp_h;
  33.      bmp_s := 320 - bmp_w; bmp_cy.w := 0;
  34.      ASM
  35.         PUSH DS
  36.         MOV DS,WORD PTR bmp2scale + 2
  37.         MOV AX,$A000; MOV ES,AX; CLD; MOV AX,320;
  38.         MUL bstrty; ADD ax,bstrtx; MOV DI,AX;
  39.        @L2:
  40.         MOV AX,bmp_cy.i; MUL actualx; MOV BX,AX;
  41.         ADD BX,WORD PTR bmp2scale;
  42.         MOV CX,bmp_w; MOV SI,0; MOV DX,bmp_sx.f;
  43.        @L:
  44.         MOV AL,[BX]; STOSB; ADD SI,DX; ADC BX,bmp_sx.i;
  45.         LOOP @L
  46.         ADD DI,bmp_s; MOV AX,bmp_sy.f; MOV bx,bmp_sy.i;
  47.         ADD bmp_cy.f,AX; ADC bmp_cy.i,BX;
  48.         DEC WORD PTR bmp_h; JNZ @L2; POP DS;
  49.      END;
  50. END;
  51.  
  52.